//
//  HomeSearchNaviView.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/3.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "HomeSearchNaviView.h"
#import "HomeSearchTextField.h"

@interface HomeSearchTextField ()<UITextFieldDelegate>

@end

@implementation HomeSearchNaviView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColorHex(0xFFFFFF);
        [self layout];
    }
    return self;
}

- (void)layout {
    
    [self addSubview:self.searchTextField];
    [self addSubview:self.searchButton];
    
    [self.searchTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.centerY.mas_equalTo(self);
        make.width.mas_equalTo(400);
        make.height.mas_equalTo(homeSearchTFHeight);
    }];
    
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.searchTextField);
        make.left.mas_equalTo(self.searchTextField.mas_right).offset(10);
    }];
    
}



- (UIButton *)searchButton {
    if (!_searchButton) {
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchButton setTitle:@"搜索" forState:UIControlStateNormal];
        [_searchButton setTitleColor:UIColorHex(0x202024) forState:UIControlStateNormal];
    }
    return _searchButton;
}

- (HomeSearchTextField *)searchTextField {
    if (!_searchTextField) {
        _searchTextField = [[HomeSearchTextField alloc] init];
        _searchTextField.placeholder = @"请输入您想要搜索的单品";
        _searchTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
        _searchTextField.returnKeyType = UIReturnKeySearch;
        _searchTextField.layer.cornerRadius = homeSearchTFHeight/2;
        _searchTextField.layer.borderWidth = 1;
        _searchTextField.layer.borderColor = UIColorHex(0x202024).CGColor;
        _searchTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fangdajing_8e8e8e"]];
        _searchTextField.leftViewMode = UITextFieldViewModeAlways;
    }
    return _searchTextField;
}
@end
